package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Apply;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class WffApplyApply implements WffBuildOp
{
  private final WffBuildOp argOp;
  private final WffBuildOp opOp;

  public WffApplyApply(WffBuildOp opOp, WffBuildOp argOp)
  {
    this.argOp = argOp;
    this.opOp = opOp;
  }

  @Override
  public IAbstract build(IAbstract[] env, Location loc, WffEngine engine)
  {
    IAbstract op = opOp.build(env, loc, engine);
    Apply args = (Apply) argOp.build(env, loc, engine);

    return new Apply(loc, op, args.getArgs());
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    opOp.prettyPrint(disp);
    disp.append("@");
    argOp.prettyPrint(disp);
  }
}
